// pages/address/list/index.js
import {
  getAddressList,
  delAddress
} from '../../../api/address'
import {
  toast
} from '../../../../../utils/extendApi'
Page({
  // 页面的初始数据
  data: {
    addressList: [1, 2, 3]
  },
  onShow() {
    this.getAddressList()
  },
  async getAddressList() {
    const {
      data
    } = await getAddressList()
    this.setData({
      addressList: data
    })


    // console.log(data[0].phone.replace(phone.substring(2, 6), '****'));
  },

  // 去编辑页面
  toEdit({
    mark: {
      id
    }
  }) {
    // console.log(id);
    wx.navigateTo({
      url: `/modules/settingModule/pages/address/add/index?id=${id}`
    })
  },
  async del({
    mark: {
      id
    }
  }) {
    await delAddress(id)
    toast({
      title: '删除成功',
      icon: 'success'
    })
    this.getAddressList()
  }
})